Skip to content

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Mar 31, 2025

What does this PR do?

This PR introduces a Windows-specific proxy binary (elastic-agent-archive-root.exe) that is placed at the root of the Elastic Agent .zip archive. The proxy acts as a thin wrapper that forwards execution to the actual agent binary located under the data/elastic-agent-{commit-sha} directory.

The proxy is built during the packaging step using a new Mage target (WindowsArchiveRootBinary), and replaces the duplicated agent binary that previously resided in the archive root due to lack of symlink support in .zip archives. This approach mimics the behavior seen on other platforms like Linux/macOS, where the root-level agent is a symlink into the versioned binary path.

This change avoids the need to duplicate the agent binary in the archive, reducing both the archive size and post-extraction disk footprint.

Why is it important?

The Windows .zip archive currently includes a full copy of the elastic-agent.exe binary at the root of the archive due to the lack of symlink support in the zip format. This duplication, increases the download size and disk footprint unnecessarily

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Disruptive User Impact

There should be no disruptive user impact. The proxy binary is fully backward-compatible with existing workflows that invoke the elastic-agent.exe binary from the root of the archive on Windows. Users should not notice any difference in behavior.

How to test this PR locally

  1. Package the windows archive

    PACKAGES=zip EXTERNAL=true PLATFORMS=windows/amd64 SNAPSHOT=true mage -v package
    
  2. Unzip the resulting .zip file and verify that:

  • The root elastic-agent.exe is a lightweight proxy (~2MB instead of 260MB+)
  • The actual binary lives under data/elastic-agent-/elastic-agent.exe
  • Running the root elastic-agent.exe launches the nested agent as expected

Related issues

Manual Testing

  1. DRA dry-run here and artifacts are produced successfully (link) (ty @pchila 🙏 )
  2. With the windows artifact from the above I directly installed a fleet-managed and agent got installed fine and reported healthy
  3. I installed a standalone agent at the version v8.17.4. Then again from the windows artifact of the above DRA I did an upgrade and this was successful

This is an automatic backport of pull request #7601 done by [Mergify](https://mergify.com).

…7601)

* feat: implement a proxy binary to be placed in the root of windows archive and invoke the nested elastic-agent binary

* fix: remove redundant returns in the code

* fix: reword error message when we cannot stat inner elastic-agent binary

* fix: use slices.Contains to check if we are building for windows/amd64

* fix: add comment to capture that CommitSHA is set at build time

* fix: rename hack folder to wrapper

* fix: reside typo

* fix: reword error message when we cannot stat inner elastic-agent binary

* ci: automate go version updates for wrapper/windows/archive-proxy/go.mod

* fix: switch logging to fmt and also log to windows event logger

* Revert "ci: automate go version updates for wrapper/windows/archive-proxy/go.mod"

This reverts commit c9a698b.

* fix: initialise windows event log only if we are admin

* fix: remove os.Stat call and rely on command.Start() to raise an error if binary is missing

* fix: remove custom logger

(cherry picked from commit 6b4b0dc)

# Conflicts:
#	dev-tools/packaging/packages.yml
@mergify mergify bot requested a review from a team as a code owner March 31, 2025 14:11
@mergify mergify bot added backport conflicts There is a conflict in the backported pull request labels Mar 31, 2025
@mergify mergify bot requested review from pchila and swiatekm and removed request for a team March 31, 2025 14:11
@mergify
Copy link
Contributor Author

mergify bot commented Mar 31, 2025

Cherry-pick of 6b4b0dc has failed:

On branch mergify/bp/8.x/pr-7601
Your branch is up to date with 'origin/8.x'.

You are currently cherry-picking commit 6b4b0dc69.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   magefile.go
	new file:   wrapper/windows/archive-proxy/go.mod
	new file:   wrapper/windows/archive-proxy/go.sum
	new file:   wrapper/windows/archive-proxy/main.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   dev-tools/packaging/packages.yml

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@github-actions github-actions bot added Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team skip-changelog labels Mar 31, 2025
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@ebeahan ebeahan enabled auto-merge (squash) March 31, 2025 14:36
@elastic-sonarqube
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 40%)

See analysis details on SonarQube

@ebeahan ebeahan merged commit 9978e40 into 8.x Mar 31, 2025
11 of 12 checks passed
@ebeahan ebeahan deleted the mergify/bp/8.x/pr-7601 branch March 31, 2025 16:38
@elasticmachine
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport conflicts There is a conflict in the backported pull request skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants